<template>
  <div>
    <van-dropdown-menu>
      <van-dropdown-item
        disabled
        title="综合"
        v-model="value1"
        :options="option1"
      />
      <van-dropdown-item
        title="价格"
        v-model="priceVal"
        :options="option2"
        @change="priceChange"
      />
      <van-dropdown-item
        title="分类"
        v-model="categoryVal"
        :options="filterCategory"
        @change="categoryChange"
      />
    </van-dropdown-menu>
    <van-empty
      v-if="goodsList.length == 0"
      image="search"
      description="没有您要搜索的商品"
    />
    <Products v-else :goodsList="goodsList" />
  </div>
</template>

<script>
import Products from "@/components/Products.vue";
import { GridItem } from "vant";
export default {
  data() {
    return {
      value1: 0,
      priceVal: "desc",
      categoryVal: 0,
      option1: [
        { text: "全部商品", value: 0 },
        { text: "新款商品", value: 1 },
        { text: "活动商品", value: 2 },
      ],
      option2: [
        { text: "价格由高到低", value: "desc" },
        { text: "价格由低到高", value: "asc" },
      ],
    };
  },
  beforeUpdate() {
    this.filterCategory.map((item) => {
      // console.log("item", item);
      if (item.checked) {
        this.categoryVal = item.value;
        return;
      }
    });
  },
  methods: {
    categoryChange(value) {
      // console.log(value);
      // 当value发生改变时 向父组件发送函数的值
      this.$emit("categoryChange", value);
    },
    priceChange(value) {
      console.log(value);
      this.$emit("priceChange", value);
    },
  },
  props: ["filterCategory", "goodsList"],
  components: {
    Products,
  },
};
</script>

<style>
</style>